<template>
  <div class="app-container">
        <el-header>
          <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect" style="float:right">
            <el-menu-item index="1" @click="toFrontIndexPage">首页</el-menu-item>
            <el-menu-item index="2" v-if="isLogin==false"  @click="toLoginPage">登录</el-menu-item>
            <el-menu-item index="3" v-if="isLogin==false" @click="toRegisterPage">注册</el-menu-item>
            <el-submenu v-if="isLogin==true" index="4">
              <template v-if="isLogin==true" slot="title">个人中心</template>
              <el-menu-item @click="toFrontUserProfilePage"  v-if="isLogin==true" index="4-1">基本信息</el-menu-item>
              <el-menu-item @click="toFrontRecordListPage"  v-if="isLogin==true" index="4-2">生成记录</el-menu-item>
              <el-menu-item @click.native="logout" v-if="isLogin==true" index="4-3">Logout</el-menu-item>
            </el-submenu>
          </el-menu>
        </el-header>



    <el-table v-loading="loading" :data="picgenerateList">
      <el-table-column label="生成时间" align="center" prop="picGenerateCreatetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.picGenerateCreatetime, '{y}-{m}-{d} {h}:{m}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生成名字" align="center" prop="picGeneratePicname" />
      <el-table-column label="生成状态" align="center" prop="picGenerateStatus" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>
<script>
import { listPicgenerate} from "@/api/pic/picgenerate";
import { getToken } from '@/utils/auth'

export default {
  name: "Picgenerate",
  data() {
    return {
      // 遮罩层
      loading: true,

      activeIndex: '1',
      activeIndex2: '2',

      isLogin :("undefined".indexOf(getToken())!==-1) ? false :true,

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        picGenerateCreatetime: null,
        picGeneratePicname: null,
        picGenerateStatus: null,
        userId: null,
        delFlat: null
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询图片生成列表 */
    getList() {
      this.loading = true;
      listPicgenerate(this.queryParams).then(response => {
        this.picgenerateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
              toLoginPage(){
                this.$router.push("/login" );
              },
              toRegisterPage(){
                this.$router.push("/register" );
              },
              toFrontIndexPage(){
                this.$router.push("/" );
              },
              toFrontUserProfilePage(){
                this.$router.push("/front/user" );
              },
              toFrontRecordListPage(){
                this.$router.push("/front/frontRecord" );
              },

              async logout() {
                this.$confirm('确定注销并退出系统吗？', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  type: 'warning'
                }).then(() => {
                  this.$store.dispatch('LogOut').then(() => {
                    location.href = '/index';
                  })
                }).catch(() => {});
              }
  }
};
</script>
